/*
day286
2020.6.9
*/
#include<iostream> 
#include<vector>
#include<algorithm>
using namespace std;

class Solution{
public: 
	vector<vector<int>> threeSum(vector<int>& nums) {
        vector<vector<int>> res;
         
        sort(nums.begin(),nums.end());

        int l=0,r=0;
        for(int i=0;i<nums.size();++i)
        {
        	if(i>0 && nums[i]==nums[i-1])
        	{
        		continue;
			}
        	l=i+1;
        	r=nums.size()-1;
        	
        	while(l<r)
        	{
        		int tem_sum=nums[l]+nums[r]+nums[i];
        		if(tem_sum==0)
        		{
        			vector<int> tem;
        			tem.push_back(nums[i]);
        			tem.push_back(nums[l]);
        			tem.push_back(nums[r]);
        			
        			res.push_back(tem);
        			while(l<r && l<nums.size()-1 && nums[l]==nums[l+1])
        			{
        				l++;
					}
        			l++;
    
				}
				else if(tem_sum<0)
				{
					l++;
				}
				else
				{
					r--;
				}
			}
		}
		return res;
    }
};


int main()
{ 
	vector<int> nums={-2,0,0,2,2};
	Solution s;
	vector<vector<int>> res=s.threeSum(nums);
	for(auto &v:res)
	{
		for(auto &m:v)
		{
			cout<<m<<'\t';
		}
		cout<<endl;
	}
	return 0;
 } 
